package cn.sola.socket.serve.thread;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * @author: kangxiaohui
 * @date：2017年12月31日 下午7:48:22
 * @version 1.0 
 * 
 */
public class WeatherThread implements Runnable {

	private Socket socket;
	
	public WeatherThread(Socket socket) {
		super();
		this.socket = socket;
	}



	@Override
	public void run() {
		DataInputStream dataInputStream = null;
		DataOutputStream dataOutputStream = null;
		try {
			System.out.println("start......");
			//接收客户端消息
			//接收客户端请求数据
			dataInputStream = new DataInputStream(socket.getInputStream());
			String cityName = dataInputStream.readUTF();
			System.out.println("来自client的请求..." + cityName);
			//像客户端发送数据
			dataOutputStream = new DataOutputStream(socket.getOutputStream());
			String result = "发送client天气的描述:晴转多云";
			dataOutputStream.writeUTF(result);
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			//释放资源
			try {
				dataInputStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				dataOutputStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
